package com.gitee.wsl.data.input.ext

import com.gitee.wsl.data.input.InputHandlerScope


/**
 * Posts an Input back to the VM to be processed later. The Input is posted from within a side-job
 * to avoid unwanted cancellation or potential deadlocks. The current InputHandler will be completed
 * before this Input is actually dispatched to the ViewModel Input queue.
 *
 * The side-job launched here uses the `.toString()` value of [input] as the key, to avoid accidentally cancelling
 * any already-running side-jobs.
 */
@Suppress("NOTHING_TO_INLINE")
suspend inline fun <Inputs : Any, Events : Any, State : Any> InputHandlerScope<Inputs, Events, State>.postInput(
    input: Inputs
) {
    sideJob(key = input.toString()) {
        this@sideJob.postInput(input)
    }
}